package org.esgl3d.rendering;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.microedition.khronos.opengles.GL10;

/**
 * @author michael
 *
 */
public class RenderCaps {
	private static Logger log = Logger.getLogger(RenderCaps.class.getName());
	
	private boolean isSoftwareRenderer = false;
	private boolean isVboSupported = false;
	private boolean isOpenGL10 = false;
	
	public boolean isSoftwareRenderer() {
		return isSoftwareRenderer;
	}
	
	public boolean isVboSupported() {
		return isVboSupported;
	}
	
	/**
	 * Checks if opengl-es 1.0 is available.
	 * @return true if available
	 */
	public boolean isOpenGL10() {
		return isOpenGL10;
	}
	
	/**
	 * Checks if opengl-es 1.1 is available
	 * @return true if available
	 */
	public boolean isOpenGL11() {
		return !isOpenGL10;
	}
	
	/**
	 * Checks if opengl-es 2.0 is available
	 * @return always false since opengl-es 2.0 is not supported
	 */
	public boolean isOpenGL20() {
		return false;
	}
	
	public void initialize(GL10 gl) {
		String extensions = gl.glGetString(GL10.GL_EXTENSIONS);
		String renderer = gl.glGetString(GL10.GL_RENDERER);
		String version = gl.glGetString(GL10.GL_VERSION);
		
		if (log.isLoggable(Level.INFO)) {
			log.info(extensions);
			log.info(renderer);
			log.info(version);
		}
		
		isSoftwareRenderer = renderer.contains("PixelFlinger");
		isOpenGL10 = version.contains("1.0");
		
		isVboSupported = !isSoftwareRenderer && (!isOpenGL10 || extensions.contains("vertex_buffer_object"));
	}
}
